<template>
  <div class="app-container">
    <div id="map"></div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="员工姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          v-hasPermi="['business:technician:query']"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:technician:add']"
          >新增</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:technician:del']"
          >批量删除</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="storeList"
      max-height="650px"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column
        label="适用区域"
        align="center"
        prop="belongAreaName"
        :show-overflow-tooltip="true"
        width="120"
      />
      <el-table-column
        label="适用门店"
        align="center"
        prop="belongStoreName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="员工姓名"
        align="center"
        prop="name"
        :show-overflow-tooltip="true"
      />

      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <span>{{ scope.row.gender == 0 ? "男" : "女" }}</span>
        </template>
      </el-table-column>

      

      <el-table-column label="头像" align="center" prop="avatar" width="120">
        <template slot-scope="scope">
          <image-preview :src="scope.row.avatar" :width="50" :height="50" />
        </template>
      </el-table-column>
  
     
      <el-table-column
        label="电话"
        align="center"
        prop="phoneNumber"
        width="120"
      />


      <el-table-column
        label="生日"
        align="center"
        prop="dateOfBirth"
        width="120"
      />

      
      <el-table-column label="工号" align="center" prop="jobNumber" />

      <el-table-column label="评分" align="center" prop="score" />
      <el-table-column label="收益" align="center" prop="totalEarnings" />
      
      <el-table-column
        label="底薪"
        align="center"
        prop="basicSalary"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="简介"
        align="center"
        prop="synopsis"
        :show-overflow-tooltip="true"
        width="200"
      />
      <el-table-column
        label="服务项目"
        align="center"
        :show-overflow-tooltip="true"
        prop="itemStoreNameStr"
      >
        <!-- <template slot-scope="scope">
          <template
            v-if="scope.row.itemStoreList && scope.row.itemStoreList.length > 0"
          >
            <span>{{ scope.row.itemStoreList[0].itemName }}</span>
          </template>
          <template v-else>
            <span>暂无</span>
          </template>
        </template> -->
      </el-table-column>
      <!-- <el-table-column label="在职状态" align="center" prop="onTheJob">
        <template slot-scope="scope">
          <span>{{ scope.row.onTheJob == "1" ? "在职" : "离职 " }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="状态" align="center" prop="statusStr" />
      
      <el-table-column label="上架" align="center" prop="state">
        <template slot-scope="scope">
          <span>{{ scope.row.state == 1 ? "上架" : "下架 " }}</span>
        </template>
      </el-table-column>

      <el-table-column label="暂停状态" align="center" prop="pauseStatus">
        <template slot-scope="scope">
          <span>{{ scope.row.pauseStatus == 1 ? "正常营业" : "已暂停 " }}</span>
        </template>
      </el-table-column>
       <el-table-column label="入职时间" align="center" prop="entryTime" /> 
       <el-table-column label="创建人"   align="center"  prop="createBy" />
      <el-table-column label="创建时间"   align="center"  prop="createTime" />
      <el-table-column label="修改人"   align="center"  prop="updateBy" />
      <el-table-column label="修改时间"   align="center"  prop="updateTime" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
        width="300"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:technician:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-plus-outline"
            @click="handleAdd2(scope.row)"
            v-hasPermi="['business:technician:addOrder']"
            >添加项目</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="handleGround(scope.row, (state = 0))"
            v-if="scope.row.state == 1"
            v-hasPermi="['business:technician:up']"
            >下架</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload2"
            @click="handleGround(scope.row, (state = 1))"
            v-if="scope.row.state == 0"
            v-hasPermi="['business:technician:offShelf']"
            >上架</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-video-play"
            @click="handlePause(scope.row, 2)"
            v-hasPermi="['business:technician:pause']"
            v-if="scope.row.pauseStatus < 2"
            >暂停</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-video-pause"
            @click="handlePause(scope.row, 1)"
            v-hasPermi="['business:technician:pause']"
            v-if="scope.row.pauseStatus > 1"
            >取消暂停</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-connection"
            v-hasPermi="['business:technician:editpass']"
            @click="updatePassword(scope.row)"
            >修改密码</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-custom"
            @click="handleGround1(scope.row)"
            v-hasPermi="['business:technician:go']"
            >{{ scope.row.onTheJob === "0" ? "入职" : "离职" }}</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:technician:del']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改门店对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="区域" prop="belongAreaId">
              <el-select
                clearable
                v-model="form.belongAreaId"
                @change="changeRegion"
              >
                <el-option
                  v-for="(item, index) of region"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="适用门店" prop="belongStoreId">
              <el-select
                clearable
                v-model="form.belongStoreId"
                @change="changeStore"
              >
                <el-option
                  v-for="(item, index) of store"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="员工姓名" prop="name">
              <el-input
                v-model="form.name"
                placeholder="请输入员工姓名"
                style="width: 222px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电话" prop="phoneNumber">
              <el-input
                v-model="form.phoneNumber"
                placeholder="请输入电话"
                style="width: 222px"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工号" prop="jobNumber">
              <el-input
                v-model="form.jobNumber"
                placeholder="请输入工号"
                style="width: 222px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保底薪资" prop="basicSalary">
              <el-input
                v-model="form.basicSalary"
                placeholder="请输入保底薪资"
                style="width: 222px"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="在职状态" prop="onTheJob">
              <el-select clearable v-model="form.onTheJob">
                <el-option
                  v-for="(item, index) of List"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="上架状态" prop="state">
              <el-select clearable v-model="form.state">
                <el-option
                  v-for="(item, index) of List2"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="社保金额" prop="socialSecurity">
              <el-input
                v-model="form.socialSecurity"
                placeholder="请输入社保金额"
                style="width: 222px"
              />
            </el-form-item>
          </el-col>

          <!-- <el-col :span="12">
            <el-form-item label="失效时间" prop="dateOfBirth">
              <el-date-picker
                clearable
                v-model="form.dateOfBirth"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择出生年月"
              >
              </el-date-picker>
            </el-form-item>
          </el-col> -->

        </el-row>


        <el-form-item label="简介" prop="synopsis">
          <el-input
            type="textarea"
            v-model="form.synopsis"
            placeholder="请输入简介"
            style="width: 650px"
          />
        </el-form-item>

        <el-form-item label="头像" prop="avatar">
          <image-upload v-model="form.avatar" :limit="1" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="入职类型" prop="entryType">
              <el-select clearable v-model="form.entryType">
                <el-option
                  v-for="(item, index) of entryType"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="gender">
              <el-select clearable v-model="form.gender">
                <el-option
                  v-for="(item, index) of gender"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="视力情况" prop="eyesight">
              <el-select clearable v-model="form.eyesight">
                <el-option
                  v-for="(item, index) of eyesight"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生年月" prop="dateOfBirth">
              <el-date-picker
                clearable
                v-model="form.dateOfBirth"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择出生年月"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="身份证正面(国徽面)"
              prop="identificationCardFront"
            >
              <image-upload v-model="form.identificationCardFront" :limit="1" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="身份证反面(人像面)"
              prop="identificationCardBack"
            >
              <image-upload v-model="form.identificationCardBack" :limit="1" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="详细地址" prop="address">
              <el-input
                type="textarea"
                v-model="form.address"
                placeholder="请输入详细地址"
                style="width: 700px"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="技师证书上传" prop="certificate">
              <image-upload v-model="form.certificate" :limit="4" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同上传" prop="contract">
              <image-upload v-model="form.contract" :limit="10" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
         
        </el-row> -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="小程序是否显示" prop="minProIsShow">
              <el-select clearable v-model="form.minProIsShow">
                <el-option
                  v-for="(item, index) of isShowList"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="入职时间" prop="entryTime">
              <el-date-picker
                clearable
                v-model="form.entryTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择入职时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加项目 -->
    <el-dialog
      :title="'添加项目'"
      :visible.sync="addOrder"
      width="700px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="form2"
        :model="orderForm"
        :rules="rules"
        label-width="120px"
      >
        <!-- <el-form-item label="添加项目" prop="zyItemList">
          <el-select multiple clearable v-model="orderForm.zyItemList">
            <el-option
              v-for="(item, index) of zyItemList"
              :key="index"
              :label="item.value"
              :value="item.key"
              >{{ item.value }}</el-option
            >
          </el-select>
        </el-form-item> -->
        <el-transfer
          :titles="['未分配', '已分配']"
          v-model="allocated"
          :data="transferList"
        ></el-transfer>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitList">确 定</el-button>
        <el-button @click="cancelList">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 修改密码 -->
    <el-dialog title="用户信息" :visible.sync="isUpdatePassword">
      <el-form ref="form2" :model="userInfo" label-width="120px">
        <el-form-item label="用户名">
          <div>{{ userInfo.nickName }}</div>
        </el-form-item>
        <el-form-item label="登录账号">
          <div>{{ userInfo.userName }}</div>
        </el-form-item>
        <el-form-item label="密码" prop="userPassword">
          <el-input
            v-model="userInfo.password"
            maxlength="6"
            minlength="6"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateUserPassword">确 定</el-button>
        <el-button @click="isUpdatePassword = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 暂停 -->
    <el-dialog title="暂停时间" :visible.sync="isPauseDialog">
      <el-form :model="pauseTime" label-width="120px">
        <el-form-item label="配置时间">
          <el-input
            v-model="pauseTime.minutes"
            @input="configured"
            placeholder="快速暂停，请输入快速暂停分钟数"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-date-picker
            style="width: 300px"
            :disabled="minutesIs"
            :picker-options="pickerOptions"
            v-model="pauseTime.beginTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="开始时间"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item label="结束时间">
          <el-date-picker
            style="width: 300px"
            :disabled="minutesIs"
            v-model="pauseTime.endTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="结束时间"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updatePause">确 定</el-button>
        <el-button @click="isPauseDialog = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listtechnician,
  gettechnician,
  delitetechnician,
  addtechnician,
  updatetechnician,
  listMemberRegion,
  listMemberStore,
  addListInTech,
  storeItemDetails,
  resign,
  entry
} from "@/api/system/personnel/technician";
import { listitemList } from "@/api/system/projectList/projectList";
import { getUser, resetUserPwd } from "@/api/system/user.js";
import { addpause } from "@/api/system/personnelMatters/pauseList.js";
export default {
  name: "Store",
  data() {
    return {
      /////////
      isShowList: [
        {
          key: "1",
          value: "是",
        },
        {
          key: "2",
          value: "否",
        },
      ],
      map: null,
      local: null,
      mk: null,
      latitude: "",
      longitude: "",
      keyWords: "",
      result: "",
      minutesIs: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 门店表格数据
      storeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        productName: null,
        storeName: null,
        storeName: null,
        phoneNumber: null,
        province: null,
        provinceString: null,
        city: null,
        cityString: null,
        county: null,
        countyString: null,
        detail: null,
        longitude: null,
        latitude: null,
        intro: null,
        images: null,
        state: null,
        isInitiate: null,
        openingTime: null,
        closingTime: null,
        entryType: null,
        gender: null,
        eyesight: null,
        identificationCardFront: null,
        identificationCardBack: null,
        dateOfBirth: null,
        address: null,
        certificate: null,
        contract: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        avatar: [{ required: true, message: "请选择头像", trigger: "blur" }],
        belongAreaId: [
          { required: true, message: "请选择所属区域", trigger: "blur" },
        ],
        entryType: [{ required: true, message: "请选择", trigger: "blur" }],
        gender: [{ required: true, message: "请选择", trigger: "blur" }],
        eyesight: [{ required: true, message: "请选择", trigger: "blur" }],
        // identificationCardFront:[
        //   { required: true, message: '请选择', trigger: 'blur' },
        // ],
        // identificationCardBack:[
        //   { required: true, message: '请选择', trigger: 'blur' },
        // ],
        belongStoreId: [
          { required: true, message: "请选择适用门店", trigger: "blur" },
        ],
        name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
          { min: 1, max: 10, message: "长度在 1到 10 个字符", trigger: "blur" },
        ],
        jobNumber: [
          { required: true, message: "请输入正确的工号", trigger: "blur" },
          { pattern: /^[0-9]+$/, message: "请输入正确的工号", trigger: "blur" },
        ],
        phoneNumber: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            pattern: /^1[3456789]\d{9}$/,
            message: "请输入有效的手机号",
            trigger: "blur",
          },
        ],
        basicSalary: [
          { required: true, message: "请输入底薪", trigger: "blur" },
          { pattern: /^[0-9]+$/, message: "底薪必须为数字", trigger: "blur" },
        ],
        state: [{ required: true, message: "请选择上架", trigger: "blur" }],
        onTheJob: [{ required: true, message: "请选择在职", trigger: "blur" }],
        state: [{ required: true, message: "请选择上架状态", trigger: "blur" }],
        synopsis: [
          { required: true, message: "请输入简介", trigger: "blur" },
          {
            min: 1,
            max: 1000,
            message: "长度在 1到 1000 个字符",
            trigger: "blur",
          },
        ],
        minProIsShow: [
          {
            required: true,
            message: "请选择是否展示小程序端",
            trigger: "blur",
          },
        ],
      },
      options: [],
      List: [
        {
          key: "1",
          value: "在职",
        },
        {
          key: "0",
          value: "离职",
        },
      ],
      //入职类型
      entryType: [
        {
          key: 1,
          value: "全职",
        },
        {
          key: 2,
          value: "兼职",
        },
      ],
      //性别
      gender: [
        {
          key: 0,
          value: "男",
        },
        {
          key: 1,
          value: "女",
        },
        {
          key: 2,
          value: "未知",
        },
      ],
      //视力情况
      eyesight: [
        {
          key: 0,
          value: "正常",
        },
        {
          key: 1,
          value: "半盲",
        },
        {
          key: 2,
          value: "全盲",
        },
      ],
      List2: [
        {
          key: "1",
          value: "上架",
        },
        {
          key: "0",
          value: "下架",
        },
      ],
      region: [],
      store: [],
      addOrder: false, //添加项目弹框
      zyItemList: [],
      orderForm: {},
      itemStoreId: "",
      technicianId: "",
      isUpdatePassword: false,
      userInfo: {
        // 修改密码
        password: "",
      },
      userRules: {
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            pattern: /^[a-zA-Z0-9]+$/,
            message: "请输入6位数字或者字母的密码",
            trigger: "blur",
          },
        ],
      },
      isPauseDialog: false,
      pauseTime: {
        minutes: "",
        beginTime: "",
        endTime: "",
      },
      selectRow: {},
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < new Date().getTime();
        },
      },
      allocated: [],
      transferList: [],
    };
  },
  created() {
    this.getList();
    this.listregion();
    listMemberStore().then((res) => {
      console.log(res, 333);
      this.store = res.data.map((rItem) => {
        return {
          key: rItem.id,
          value: rItem.storeName,
        };
      });
    });
  },
  methods: {
    configured() {
      if (this.pauseTime.minutes != "") {
        this.minutesIs = true;
        this.pauseTime.beginTime = new Date();
        this.pauseTime.endTime = new Date(
          this.pauseTime.beginTime.getTime() +
            this.pauseTime.minutes * 60 * 1000
        );

        this.pauseTime.beginTime = this.pauseTime.beginTime
          .toLocaleString()
          .replaceAll("/", "-");
        this.pauseTime.endTime = this.pauseTime.endTime
          .toLocaleString()
          .replaceAll("/", "-");
      } else {
        this.minutesIs = false;
        this.pauseTime.beginTime = "";
        this.pauseTime.endTime = "";
      }
    },

    updatePause() {
      let { beginTime, endTime } = this.pauseTime;

      if (!this.pauseTime.beginTime) {
        this.$message({
          type: "warning",
          message: "请输入开始时间",
        });

        return;
      }

      if (!this.pauseTime.endTime) {
        this.$message({
          type: "warning",
          message: "请输入结束时间",
        });

        return;
      }

      if (new Date(endTime).getTime() <= new Date(beginTime).getTime()) {
        this.$message({
          type: "warning",
          message: "结束时间不能小于开始时间",
        });
        return;
      }
      let {
        userId,
        name,
        phoneNumber,
        belongAreaId,
        belongAreaName,
        belongStoreId,
        belongStoreName,
      } = this.selectRow;
      addpause({
        userId,
        userName: name,
        phoneNumber,
        regionId: belongAreaId,
        regionName: belongAreaName,
        storeId: belongStoreId,
        storeName: belongStoreName,
        beginTime,
        endTime,
      }).then((response) => {
        if (response.code == 200) {
          this.$modal.msgSuccess("暂停成功");
        }
        this.isPauseDialog = false;
        this.getList();
      });
    },
    updatePassword(row) {
      this.isUpdatePassword = true;
      getUser(row.userId).then((res) => {
        console.log(res);
        this.userInfo = res.data;
        this.userInfo.password = "";
      });
    },
    updateUserPassword() {
      let rules = /^[a-zA-Z0-9]+$/;
      if (rules.test(this.userInfo.password)) {
        resetUserPwd(this.userInfo.userId, this.userInfo.password).then(
          (res) => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "修改成功,密码为：" + this.userInfo.password,
              });
              this.isUpdatePassword = false;
              this.getList();
            }
          }
        );
      } else {
        this.$message({
          type: "info",
          message: "请输入数字或者字母的6位数密码",
        });
      }
    },
    listregion() {
      listMemberRegion().then((res) => {
        console.log(res, 3333);
        this.region = res.data.map((rItem) => {
          return {
            key: rItem.id,
            value: rItem.regionName,
          };
        });
      });
    },
    changeRegion(value) {
      const selectedOption = this.region.find((item) => item.key === value);
      const selectedKey = selectedOption.key;
      const selectedValue = selectedOption.value;
      this.form.belongAreaName = selectedValue;
      listMemberStore({ regionId: value }).then((res) => {
        console.log(res, 333);
        this.store = res.data.map((rItem) => {
          return {
            key: rItem.id,
            value: rItem.storeName,
          };
        });
      });
    },
    changeStore(value) {
      const selectedOption = this.store.find((item) => item.key === value);
      const selectedKey = selectedOption.key;
      const selectedValue = selectedOption.value;
      this.form.belongStoreName = selectedValue;
      console.log(this.form.belongStoreName, 555);
    },
    /** 查询门店列表 */
    getList() {
      console.log("1");
      this.loading = true;
      listtechnician(this.queryParams).then((response) => {
        this.storeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        storeName: null,
        phoneNumber: null,
        province: null,
        provinceString: null,
        city: null,
        cityString: null,
        county: null,
        countyString: null,
        detail: null,
        longitude: null,
        latitude: null,
        intro: null,
        images: null,
        state: null,
        isInitiate: null,
        openingTime: null,
        closingTime: null,
        createTime: null,
        updateTime: null,
        entryType: null,
        gender: null,
        eyesight: null,
        identificationCardFront: null,
        identificationCardBack: null,
        dateOfBirth: null,
        address: null,
        certificate: null,
        contract: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.store = [];
      this.open = true;
      this.title = "添加技师";
    },
    handleAdd2(row) {
      this.getList();
      this.addOrder = true;
      this.itemStoreId = row.belongStoreId;
      this.technicianId = row.id;
      storeItemDetails({
        storeId: row.belongStoreId,
        technicianId: row.id,
      }).then((res) => {
        console.log(res);
        let { allocated, undistributed } = res.data;
        let list1 = undistributed.map((ele) => {
          return {
            key: ele.id,
            label: ele.itemName,
          };
        });
        let list2 = allocated.map((ele) => {
          return {
            key: ele.id,
            label: ele.itemName,
          };
        });
        this.transferList = [...list2, ...list1];
        this.allocated = allocated.map((ele) => {
          return ele.id;
        });
      });
    },
    submitList() {
      console.log(this.allocated);
      const params = {
        zyItemList: this.allocated,
        itemStoreId: this.itemStoreId,
        technicianId: this.technicianId,
      };
      addListInTech(params).then((res) => {
        console.log(res, 123);
        if (res.code == 200) {
          this.addOrder = false;
          this.$message.success(res.msg);
          this.reset2();
        }
      });
    },
    reset2() {
      this.orderForm = {
        technicianId: null,
        itemStoreId: null,
        zyItemList: null,
      };
    },
    cancelList() {
      this.addOrder = false;
      this.reset2();
    },
    // 上下架
    handleGround1(row) {
      const params = {
        id: row.id,
        onTheJob: row.onTheJob === "0" ? "1" : "0",
      };

      if(row.onTheJob === "0" ){
        params.jobNumber= row.jobNumber;
         entry(params).then((res) => {
            this.$message({
              type: "success",
              message: `入职成功!`,
            });
            this.getList();
          });
      }else{
        this.$confirm(
        `辞职将释放工号, 是否继续?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
            resign(params).then((res) => {
            this.$message({
              type: "success",
              message: `${row.onTheJob === "0" ? "入职" : "离职"}成功!`,
            });
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: `已取消${row.onTheJob === "0" ? "入职" : "离职"}`,
          });
        });
      }
  
    },

    handlePause(row, state) {
      this.minutesIs = false;
      const params = {
        id: row.id,
        pauseStatus: state,
      };
      if (state == 2) {
        this.isPauseDialog = true;
        this.pauseTime = {
          beginTime: "",
          endTime: "",
        };
        this.selectRow = row;
        return;
      }
      this.$confirm(
        `此操作将${state === 2 ? "暂停" : "取消暂停"}该技师, 是否继续?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          updatetechnician(params).then((res) => {
            this.$message({
              type: "success",
              message: `${state === 2 ? "暂停" : "取消暂停"}成功!`,
            });
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "操作失败",
          });
        });
    },
    handleGround(row, state) {
      const params = {
        id: row.id,
        state: state,
      };
      this.$confirm(
        `此操作将${state === 1 ? "上架" : "下架"}该技师, 是否继续?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          updatetechnician(params).then((res) => {
            this.$message({
              type: "success",
              message: `${state === 1 ? "上架" : "下架"}成功!`,
            });
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消上架下架",
          });
        });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      listMemberStore({ regionId: row.belongAreaId }).then((res) => {
        this.store = res.data.map((rItem) => {
          return {
            key: rItem.id,
            value: rItem.storeName,
          };
        });
      });
      gettechnician(id).then((response) => {
        this.form = response.data;
        const storeIndex = this.store.findIndex(
          (item) => item.id == response.data.belongStoreId
        );
        const belongIndex = this.region.findIndex(
          (item) => item.id == response.data.belongAreaId
        );
        // if (storeIndex == -1) {
        //   this.form.belongStoreId = response.data.belongStoreName
        // }
        // if (belongIndex == -1) {
        //   this.form.belongAreaId = response.data.belongAreaName
        // }
        this.open = true;
        this.title = "修改技师";
        this.changeStore(response.data.belongAreaId);
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updatetechnician(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.phoneNumber = parseInt(this.form.phoneNumber);
            addtechnician(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handReset(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认重置编号为"' + ids + '"的数据项？')
        .then(function () {
          return listResetPwd({ userId: ids });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("重置成功");
        })
        .catch(() => {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除编号为"' + ids + '"的数据项？')
        .then(function () {
          return delitetechnician(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/store/export",
        {
          ...this.queryParams,
        },
        `store_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
